package cn.sxt.sys.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.sxt.sys.service.LogInfoService;
import cn.sxt.sys.utils.DataGridView;
import cn.sxt.sys.vo.LogInfoVo;

@Controller
@RequestMapping("logInfo")
public class LogInfoController {

	@Autowired
	private LogInfoService logInfoService;

	// 跳到日志管理logInfoManager.jsp
	@RequestMapping("toLogInfoManager")
	public String toLogInfoManager() {
		return "system/logInfo/logInfoManager";
	}

	// 登陆日志全查询，分页，模糊
	@RequestMapping("queryAllLogInfo")
	@ResponseBody
	public DataGridView queryAllLogInfo(LogInfoVo logInfoVo) {
		return logInfoService.queryAllLogInfo(logInfoVo);
	}

	// 删除日志
	@RequestMapping("deleteLogInfo")
	@ResponseBody
	public Map<String, Object> deleteLogInfo(LogInfoVo logInfoVo) {
		Map<String, Object> map = new HashMap<>();
		String msg = "";
		try {
			int i = logInfoService.deleteLogInfoById(logInfoVo);
			if (i > 0) {
				msg = "删除成功";
			} else {
				msg = "删除失败";
			}
		} catch (Exception e) {
			e.printStackTrace();
			msg = "删除失败";
		}
		map.put("msg", msg);
		return map;
	}

	// 批量删除日志
	@RequestMapping("batchDeleteLogInfo")
	@ResponseBody
	public Map<String, Object> batchDeleteLogInfo(LogInfoVo logInfoVo) {
		Map<String, Object> map = new HashMap<>();
		String msg = "";
		try {
			Integer[] ids = logInfoVo.getIds();
			if (ids != null && ids.length > 0) {
				for (int i = 0; i < ids.length; i++) {
					logInfoVo.setId(ids[i]);
					int j = logInfoService.deleteLogInfoById(logInfoVo);
					if (j > 0) {
						msg = "删除成功";
					} else {
						msg = "删除失败";
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			msg = "删除失败";
		}
		map.put("msg", msg);
		return map;
	}
}
